INCLUDE(${PROJECT_SOURCE_DIR}/cmake/TARGET.cmake)

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEBUG_CFLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEBUG_CFLAGS}")

SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/output CACHE PATH "Path for libraries")

add_library(_boot STATIC bootinfo.c early.c head.S) 

SET(BOOT_SCRIPT_LD ${CMAKE_SOURCE_DIR}/boot/${ARCH}/boot.ld)

#enable_language(ASM)
set_property(SOURCE head.S PROPERTY LANGUAGE C)
set_property(SOURCE head.S PROPERTY COMPILE_FLAGS "-D__ASSEMBLY__")

set(CMAKE_C_FLAGS "${DEBUG_CFLAGS} -O0 -march=armv5te -mcpu=arm926ej-s -marm -mfloat-abi=softfp")

SET_TARGET_PROPERTIES(_boot PROPERTIES LINK_FLAGS "-r")

ADD_CUSTOM_TARGET (gobee_img  ALL)

add_dependencies( gobee_img _boot )

add_custom_command(
                   TARGET gobee_img
                   COMMAND pushd ${LIBRARY_OUTPUT_PATH} && ${CMAKE_LINKER} -b binary -m armelf -r -o kernel.o brain && popd
                   COMMAND ${CMAKE_LINKER} -b elf32-littlearm  -m armelf -T ${BOOT_SCRIPT_LD}  -o ${LIBRARY_OUTPUT_PATH}/brain.elf --start-group ${LIBRARY_OUTPUT_PATH}/lib_boot.a --end-group ${LIBRARY_OUTPUT_PATH}/kernel.o
                   COMMAND ${CMAKE_OBJCOPY} -O binary -R .note -R .comments -S ${LIBRARY_OUTPUT_PATH}/brain.elf ${LIBRARY_OUTPUT_PATH}/brain.img
                   COMMENT "Generating Brain.bin"
                   )

INCLUDE(CPack)

ENABLE_TESTING()

